#!/bin/bash
# script name: 容器镜像批量保存脚本
# author: subushi
# update date: 2025.06.04

# 生成镜像列表
docker images --format "{{.Repository}}:{{.Tag}}" | grep -v "<none>" > image-list.txt

# 批量保存
mkdir -p saved-images && cd saved-images
while read -r image; do
    filename=$(echo "$image" | sed 's/[^a-zA-Z0-9._-]/_/g').tar
    echo "正在保存: $image => $filename"
    docker save -o "$filename" "$image" || echo "保存失败: $image"
done < ../image-list.txt

# 打包压缩
#tar -czvf ../all-images.tar.gz *.tar

echo "所有镜像已保存到: saved-images/"